name: Formatter and linter

on:
  push:
    branches: [ master, dev ]
  pull_request:
    branches: [ '**' ]

env:
  CARGO_TERM_COLOR: always

jobs:
  test:

    runs-on: ubuntu-latest

    steps:
    - name: Install minimal nightly (only for fmt)
      uses: dtolnay/rust-toolchain@nightly
      with:
        components: rustfmt
    - name: Install minimal stable
      uses: dtolnay/rust-toolchain@stable
      with:
        components: rustfmt, clippy
    - uses: actions/checkout@v4
    - uses: Swatinem/rust-cache@v2
      with:
        key: clippy
    - name: Install dependencies
      run: sudo apt-get install clang protobuf-compiler libunwind-dev
    - name: Check code formatting
      run: cargo +nightly fmt --all -- --check
    - name: Check cargo clippy warnings
      run: cargo clippy --workspace --all-targets --all-features -- -D warnings
